package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.PersonBase.WormBean;
import com.project.mapper.IWormMapper;
import com.project.service.IWormService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class IWormServiceImpl extends ServiceImpl<IWormMapper, WormBean> implements IWormService {
    @Override
    public IPage<WormBean> findWorm(int pageNo, int pageSize, String wormName, String wormHost) {

        Page<WormBean> page = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper<>();

        if (wormName != null){
            wrapper.like("worm_name",wormName);
        }
        if (wormHost != null){
            wrapper.like("worm_host",wormHost);
        }

        IPage<WormBean> wormBeanIPage = this.baseMapper.selectPage(page,wrapper);
        return wormBeanIPage;
    }

    @Override
    public void addWorm(WormBean wormBean) {

        this.baseMapper.insert(wormBean);

    }

    @Override
    public WormBean findWormById(int wormId) {

        WormBean wormBean = this.baseMapper.selectById(wormId);
        return wormBean;

    }
}
